﻿@model IList<Sealight.Core.DataAdapter.product_category>
@{
    ViewBag.Title = "Quản lý loại sản phẩm";
    Layout = "~/Areas/Admin/Views/Shared/__AdminLayout.cshtml";
}
<script type="text/javascript">
    $(document).ready(function () {

        $('a.delete-category').click(function () {

            var _that = this;
            var id = $(this).attr('rel');

            JsUtils.cidxQuestionDialog('Bạn chắc chắn muốn xóa?', function () {

                JsUtils.ShowLoader('#listCategory', 'Xóa...');
                $.ajax({
                    type: "POST",
                    url: "/admin/product/_DeleteCategory",
                    data: ({ id: id }),
                    dataType: "json",
                    success: function (d) {
                        if (d != null) {

                            if (d.OperationComplete != null && d.OperationComplete == false && d.ErrorCode != null) {
                                if (d.ErrorFriendlyMessage != null) {
                                    ShowErrorMessage(d.ErrorFriendlyMessage);
                                }
                                return;
                            }
                            else {
                                $(_that).parents('td').parents('tr').remove();
                                //window.location.reload();
                            }
                        }
                    },
                    complete: function (d) {
                        JsUtils.hideLoader('#listCategory');
                    },
                    cache: false
                }); //end .ajax call

            });
        });

    });
</script>
<h2>
    Quản lý loại sản phẩm</h2>
<input type="button" onclick="location.href='/admin/product/AddUpdateCategoryPage'"
    value="Thêm mới" id="btnAddNew" class="adminButtonBlue" title="Thêm mới thuộc tính cho sản phẩm" />
<div>
    <table class="tablestyle" cellspacing="0" rules="all" border="1" id="listCategory" style="width: 100%;
        border-collapse: collapse;">
        <tbody>
            <tr class="headerstyle">
                <th scope="col">
                    Tên Loại
                </th>
                <th align="center" scope="col">
                    Thứ tự hiển thị
                </th>
                <th align="center" scope="col">
                    Published
                </th>
                <th align="center" scope="col">
                    Xem
                </th>
                <th align="center" scope="col">
                    Xóa
                </th>
            </tr>
            @if (Model != null)
            {
                foreach (var d in Model)
                {
                <tr class="rowstyle">
                    <td style="width: 35%;">
                        @d.name
                    </td>
                    <td align="center" style="width: 15%;">
                        @d.display_order
                    </td>
                    <td align="center" style="width: 10%;">
                        <img id="" src="/content/images/checked.gif" alt="True" style="border-width: 0px;">
                        <span style="display: none;">
                            <input type="checkbox" checked="checked" /></span>
                    </td>
                    <td align="center" style="width: 10%;">
                        <a href="/admin/product/AddUpdateCategoryPage/@d.id" title="View">Xem</a>
                    </td>
                    <td align="center" style="width: 10%;">
                        <a href="javascript:void(0);" class="delete-category"  rel="@d.id">Xóa </a>
                    </td>
                </tr>

                    if (d.childrens != null)
                    {
                        foreach (var child in d.childrens)
                        {
                <tr class="rowstyle">
                    <td style="width: 35%;">
                        --@child.name
                    </td>
                    <td align="center" style="width: 15%;">
                        @child.display_order
                    </td>
                    <td align="center" style="width: 10%;">
                        <img id="" src="/content/images/checked.gif" alt="True" style="border-width: 0px;">
                        <span style="display: none;">
                            <input type="checkbox" checked="checked" /></span>
                    </td>
                    <td align="center" style="width: 10%;">
                        <a href="/admin/product/AddUpdateCategoryPage/@child.id" title="View">Xem</a>
                    </td>
                    <td align="center" style="width: 10%;">
                        <a href="javascript:void(0);" class="delete-category"  rel="@child.id">Xóa </a>
                    </td>
                </tr>
                        }
                    }
                }
            }
        </tbody>
    </table>
</div>
